{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3.13---表格样式创建\n",
    "\n",
    "## 表格视觉样式：DataFrame.style --->返回pandas.Styler对象的属性，具有格式化和显示DataFrame的有用方法\n",
    "## 样式创建：\n",
    "### 1.Styler.applymap: elementwise ---> 按照元素的方式处理DataFrame\n",
    "### 2.Style.apply: column- / row- / table-wise ---> 按行 / 列处理DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<pandas.io.formats.style.Styler object at 0x0000026082B79668> \t <class 'pandas.io.formats.style.Styler'>\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<style  type=\"text/css\" >\n",
       "</style>  \n",
       "<table id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5\" > \n",
       "<thead>    <tr> \n",
       "        <th class=\"blank level0\" ></th> \n",
       "        <th class=\"col_heading level0 col0\" >a</th> \n",
       "        <th class=\"col_heading level0 col1\" >b</th> \n",
       "        <th class=\"col_heading level0 col2\" >c</th> \n",
       "        <th class=\"col_heading level0 col3\" >d</th> \n",
       "    </tr></thead> \n",
       "<tbody>    <tr> \n",
       "        <th id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5level0_row0\" class=\"row_heading level0 row0\" >0</th> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row0_col0\" class=\"data row0 col0\" >-0.23073</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row0_col1\" class=\"data row0 col1\" >-1.15253</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row0_col2\" class=\"data row0 col2\" >0.284767</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row0_col3\" class=\"data row0 col3\" >0.225296</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5level0_row1\" class=\"row_heading level0 row1\" >1</th> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row1_col0\" class=\"data row1 col0\" >0.0533441</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row1_col1\" class=\"data row1 col1\" >1.04581</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row1_col2\" class=\"data row1 col2\" >-1.04923</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row1_col3\" class=\"data row1 col3\" >0.418713</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5level0_row2\" class=\"row_heading level0 row2\" >2</th> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row2_col0\" class=\"data row2 col0\" >-0.268366</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row2_col1\" class=\"data row2 col1\" >0.304776</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row2_col2\" class=\"data row2 col2\" >-0.917374</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row2_col3\" class=\"data row2 col3\" >-1.84995</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5level0_row3\" class=\"row_heading level0 row3\" >3</th> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row3_col0\" class=\"data row3 col0\" >-1.6807</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row3_col1\" class=\"data row3 col1\" >-0.489752</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row3_col2\" class=\"data row3 col2\" >0.00459406</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row3_col3\" class=\"data row3 col3\" >0.646842</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5level0_row4\" class=\"row_heading level0 row4\" >4</th> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row4_col0\" class=\"data row4 col0\" >-1.57819</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row4_col1\" class=\"data row4 col1\" >-1.30899</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row4_col2\" class=\"data row4 col2\" >-0.641586</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row4_col3\" class=\"data row4 col3\" >-1.10718</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5level0_row5\" class=\"row_heading level0 row5\" >5</th> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row5_col0\" class=\"data row5 col0\" >1.9277</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row5_col1\" class=\"data row5 col1\" >0.0218769</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row5_col2\" class=\"data row5 col2\" >0.349648</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row5_col3\" class=\"data row5 col3\" >0.170425</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5level0_row6\" class=\"row_heading level0 row6\" >6</th> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row6_col0\" class=\"data row6 col0\" >-0.321177</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row6_col1\" class=\"data row6 col1\" >1.25042</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row6_col2\" class=\"data row6 col2\" >0.889758</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row6_col3\" class=\"data row6 col3\" >0.682751</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5level0_row7\" class=\"row_heading level0 row7\" >7</th> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row7_col0\" class=\"data row7 col0\" >-1.2752</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row7_col1\" class=\"data row7 col1\" >0.0601818</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row7_col2\" class=\"data row7 col2\" >-0.315165</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row7_col3\" class=\"data row7 col3\" >-2.41086</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5level0_row8\" class=\"row_heading level0 row8\" >8</th> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row8_col0\" class=\"data row8 col0\" >1.55271</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row8_col1\" class=\"data row8 col1\" >-0.408844</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row8_col2\" class=\"data row8 col2\" >-0.230754</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row8_col3\" class=\"data row8 col3\" >0.166473</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5level0_row9\" class=\"row_heading level0 row9\" >9</th> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row9_col0\" class=\"data row9 col0\" >0.797423</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row9_col1\" class=\"data row9 col1\" >1.41495</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row9_col2\" class=\"data row9 col2\" >-0.240908</td> \n",
       "        <td id=\"T_55f7c8e4_43c7_11e8_81be_c821585077f5row9_col3\" class=\"data row9 col3\" >-0.0387529</td> \n",
       "    </tr></tbody> \n",
       "</table> "
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x26082b79668>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 样式\n",
    "\n",
    "df = pd.DataFrame(np.random.randn(10,4),columns = list('abcd'))\n",
    "style = df.style\n",
    "print(style,'\\t',type(style))\n",
    "# 查看样式及其类型\n",
    "\n",
    "style\n",
    "# 显示样式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style  type=\"text/css\" >\n",
       "    #T_17acceae_43c8_11e8_b685_c821585077f5row0_col0 {\n",
       "            color:  red;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row0_col1 {\n",
       "            color:  red;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row0_col2 {\n",
       "            color:  black;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row0_col3 {\n",
       "            color:  black;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row1_col0 {\n",
       "            color:  black;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row1_col1 {\n",
       "            color:  black;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row1_col2 {\n",
       "            color:  red;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row1_col3 {\n",
       "            color:  black;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row2_col0 {\n",
       "            color:  red;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row2_col1 {\n",
       "            color:  black;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row2_col2 {\n",
       "            color:  red;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row2_col3 {\n",
       "            color:  red;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row3_col0 {\n",
       "            color:  red;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row3_col1 {\n",
       "            color:  red;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row3_col2 {\n",
       "            color:  black;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row3_col3 {\n",
       "            color:  black;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row4_col0 {\n",
       "            color:  red;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row4_col1 {\n",
       "            color:  red;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row4_col2 {\n",
       "            color:  red;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row4_col3 {\n",
       "            color:  red;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row5_col0 {\n",
       "            color:  black;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row5_col1 {\n",
       "            color:  black;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row5_col2 {\n",
       "            color:  black;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row5_col3 {\n",
       "            color:  black;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row6_col0 {\n",
       "            color:  red;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row6_col1 {\n",
       "            color:  black;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row6_col2 {\n",
       "            color:  black;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row6_col3 {\n",
       "            color:  black;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row7_col0 {\n",
       "            color:  red;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row7_col1 {\n",
       "            color:  black;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row7_col2 {\n",
       "            color:  red;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row7_col3 {\n",
       "            color:  red;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row8_col0 {\n",
       "            color:  black;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row8_col1 {\n",
       "            color:  red;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row8_col2 {\n",
       "            color:  red;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row8_col3 {\n",
       "            color:  black;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row9_col0 {\n",
       "            color:  black;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row9_col1 {\n",
       "            color:  black;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row9_col2 {\n",
       "            color:  red;\n",
       "        }    #T_17acceae_43c8_11e8_b685_c821585077f5row9_col3 {\n",
       "            color:  red;\n",
       "        }</style>  \n",
       "<table id=\"T_17acceae_43c8_11e8_b685_c821585077f5\" > \n",
       "<thead>    <tr> \n",
       "        <th class=\"blank level0\" ></th> \n",
       "        <th class=\"col_heading level0 col0\" >a</th> \n",
       "        <th class=\"col_heading level0 col1\" >b</th> \n",
       "        <th class=\"col_heading level0 col2\" >c</th> \n",
       "        <th class=\"col_heading level0 col3\" >d</th> \n",
       "    </tr></thead> \n",
       "<tbody>    <tr> \n",
       "        <th id=\"T_17acceae_43c8_11e8_b685_c821585077f5level0_row0\" class=\"row_heading level0 row0\" >0</th> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row0_col0\" class=\"data row0 col0\" >-0.23073</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row0_col1\" class=\"data row0 col1\" >-1.15253</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row0_col2\" class=\"data row0 col2\" >0.284767</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row0_col3\" class=\"data row0 col3\" >0.225296</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_17acceae_43c8_11e8_b685_c821585077f5level0_row1\" class=\"row_heading level0 row1\" >1</th> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row1_col0\" class=\"data row1 col0\" >0.0533441</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row1_col1\" class=\"data row1 col1\" >1.04581</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row1_col2\" class=\"data row1 col2\" >-1.04923</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row1_col3\" class=\"data row1 col3\" >0.418713</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_17acceae_43c8_11e8_b685_c821585077f5level0_row2\" class=\"row_heading level0 row2\" >2</th> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row2_col0\" class=\"data row2 col0\" >-0.268366</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row2_col1\" class=\"data row2 col1\" >0.304776</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row2_col2\" class=\"data row2 col2\" >-0.917374</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row2_col3\" class=\"data row2 col3\" >-1.84995</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_17acceae_43c8_11e8_b685_c821585077f5level0_row3\" class=\"row_heading level0 row3\" >3</th> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row3_col0\" class=\"data row3 col0\" >-1.6807</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row3_col1\" class=\"data row3 col1\" >-0.489752</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row3_col2\" class=\"data row3 col2\" >0.00459406</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row3_col3\" class=\"data row3 col3\" >0.646842</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_17acceae_43c8_11e8_b685_c821585077f5level0_row4\" class=\"row_heading level0 row4\" >4</th> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row4_col0\" class=\"data row4 col0\" >-1.57819</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row4_col1\" class=\"data row4 col1\" >-1.30899</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row4_col2\" class=\"data row4 col2\" >-0.641586</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row4_col3\" class=\"data row4 col3\" >-1.10718</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_17acceae_43c8_11e8_b685_c821585077f5level0_row5\" class=\"row_heading level0 row5\" >5</th> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row5_col0\" class=\"data row5 col0\" >1.9277</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row5_col1\" class=\"data row5 col1\" >0.0218769</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row5_col2\" class=\"data row5 col2\" >0.349648</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row5_col3\" class=\"data row5 col3\" >0.170425</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_17acceae_43c8_11e8_b685_c821585077f5level0_row6\" class=\"row_heading level0 row6\" >6</th> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row6_col0\" class=\"data row6 col0\" >-0.321177</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row6_col1\" class=\"data row6 col1\" >1.25042</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row6_col2\" class=\"data row6 col2\" >0.889758</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row6_col3\" class=\"data row6 col3\" >0.682751</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_17acceae_43c8_11e8_b685_c821585077f5level0_row7\" class=\"row_heading level0 row7\" >7</th> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row7_col0\" class=\"data row7 col0\" >-1.2752</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row7_col1\" class=\"data row7 col1\" >0.0601818</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row7_col2\" class=\"data row7 col2\" >-0.315165</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row7_col3\" class=\"data row7 col3\" >-2.41086</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_17acceae_43c8_11e8_b685_c821585077f5level0_row8\" class=\"row_heading level0 row8\" >8</th> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row8_col0\" class=\"data row8 col0\" >1.55271</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row8_col1\" class=\"data row8 col1\" >-0.408844</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row8_col2\" class=\"data row8 col2\" >-0.230754</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row8_col3\" class=\"data row8 col3\" >0.166473</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_17acceae_43c8_11e8_b685_c821585077f5level0_row9\" class=\"row_heading level0 row9\" >9</th> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row9_col0\" class=\"data row9 col0\" >0.797423</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row9_col1\" class=\"data row9 col1\" >1.41495</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row9_col2\" class=\"data row9 col2\" >-0.240908</td> \n",
       "        <td id=\"T_17acceae_43c8_11e8_b685_c821585077f5row9_col3\" class=\"data row9 col3\" >-0.0387529</td> \n",
       "    </tr></tbody> \n",
       "</table> "
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x2608309b320>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 按照元素处理样式：style.applymap()\n",
    "\n",
    "def color_neg_red(val):\n",
    "    if val < 0:\n",
    "        color = 'red'\n",
    "    else:\n",
    "        color = 'black'\n",
    "    return('color: %s'% color)\n",
    "df.style.applymap(color_neg_red)\n",
    "# 创建样式方法，使得小于0的数变成红色\n",
    "# style.applemap(): ---> 自动调用其中的函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style  type=\"text/css\" >\n",
       "    #T_59206740_43c9_11e8_ba52_c821585077f5row6_col2 {\n",
       "            background-color:  yellow;\n",
       "        }    #T_59206740_43c9_11e8_ba52_c821585077f5row9_col1 {\n",
       "            background-color:  yellow;\n",
       "        }</style>  \n",
       "<table id=\"T_59206740_43c9_11e8_ba52_c821585077f5\" > \n",
       "<thead>    <tr> \n",
       "        <th class=\"blank level0\" ></th> \n",
       "        <th class=\"col_heading level0 col0\" >a</th> \n",
       "        <th class=\"col_heading level0 col1\" >b</th> \n",
       "        <th class=\"col_heading level0 col2\" >c</th> \n",
       "        <th class=\"col_heading level0 col3\" >d</th> \n",
       "    </tr></thead> \n",
       "<tbody>    <tr> \n",
       "        <th id=\"T_59206740_43c9_11e8_ba52_c821585077f5level0_row0\" class=\"row_heading level0 row0\" >0</th> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row0_col0\" class=\"data row0 col0\" >-0.23073</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row0_col1\" class=\"data row0 col1\" >-1.15253</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row0_col2\" class=\"data row0 col2\" >0.284767</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row0_col3\" class=\"data row0 col3\" >0.225296</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_59206740_43c9_11e8_ba52_c821585077f5level0_row1\" class=\"row_heading level0 row1\" >1</th> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row1_col0\" class=\"data row1 col0\" >0.0533441</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row1_col1\" class=\"data row1 col1\" >1.04581</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row1_col2\" class=\"data row1 col2\" >-1.04923</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row1_col3\" class=\"data row1 col3\" >0.418713</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_59206740_43c9_11e8_ba52_c821585077f5level0_row2\" class=\"row_heading level0 row2\" >2</th> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row2_col0\" class=\"data row2 col0\" >-0.268366</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row2_col1\" class=\"data row2 col1\" >0.304776</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row2_col2\" class=\"data row2 col2\" >-0.917374</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row2_col3\" class=\"data row2 col3\" >-1.84995</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_59206740_43c9_11e8_ba52_c821585077f5level0_row3\" class=\"row_heading level0 row3\" >3</th> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row3_col0\" class=\"data row3 col0\" >-1.6807</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row3_col1\" class=\"data row3 col1\" >-0.489752</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row3_col2\" class=\"data row3 col2\" >0.00459406</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row3_col3\" class=\"data row3 col3\" >0.646842</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_59206740_43c9_11e8_ba52_c821585077f5level0_row4\" class=\"row_heading level0 row4\" >4</th> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row4_col0\" class=\"data row4 col0\" >-1.57819</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row4_col1\" class=\"data row4 col1\" >-1.30899</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row4_col2\" class=\"data row4 col2\" >-0.641586</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row4_col3\" class=\"data row4 col3\" >-1.10718</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_59206740_43c9_11e8_ba52_c821585077f5level0_row5\" class=\"row_heading level0 row5\" >5</th> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row5_col0\" class=\"data row5 col0\" >1.9277</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row5_col1\" class=\"data row5 col1\" >0.0218769</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row5_col2\" class=\"data row5 col2\" >0.349648</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row5_col3\" class=\"data row5 col3\" >0.170425</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_59206740_43c9_11e8_ba52_c821585077f5level0_row6\" class=\"row_heading level0 row6\" >6</th> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row6_col0\" class=\"data row6 col0\" >-0.321177</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row6_col1\" class=\"data row6 col1\" >1.25042</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row6_col2\" class=\"data row6 col2\" >0.889758</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row6_col3\" class=\"data row6 col3\" >0.682751</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_59206740_43c9_11e8_ba52_c821585077f5level0_row7\" class=\"row_heading level0 row7\" >7</th> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row7_col0\" class=\"data row7 col0\" >-1.2752</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row7_col1\" class=\"data row7 col1\" >0.0601818</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row7_col2\" class=\"data row7 col2\" >-0.315165</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row7_col3\" class=\"data row7 col3\" >-2.41086</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_59206740_43c9_11e8_ba52_c821585077f5level0_row8\" class=\"row_heading level0 row8\" >8</th> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row8_col0\" class=\"data row8 col0\" >1.55271</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row8_col1\" class=\"data row8 col1\" >-0.408844</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row8_col2\" class=\"data row8 col2\" >-0.230754</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row8_col3\" class=\"data row8 col3\" >0.166473</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_59206740_43c9_11e8_ba52_c821585077f5level0_row9\" class=\"row_heading level0 row9\" >9</th> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row9_col0\" class=\"data row9 col0\" >0.797423</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row9_col1\" class=\"data row9 col1\" >1.41495</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row9_col2\" class=\"data row9 col2\" >-0.240908</td> \n",
       "        <td id=\"T_59206740_43c9_11e8_ba52_c821585077f5row9_col3\" class=\"data row9 col3\" >-0.0387529</td> \n",
       "    </tr></tbody> \n",
       "</table> "
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x2608309b6a0>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 按照行 / 列处理样式\n",
    "\n",
    "def highlight_max(s):\n",
    "    is_max = s ==s.max()\n",
    "    # print(is_max)\n",
    "    lst = []\n",
    "    for v in is_max:\n",
    "        if v:\n",
    "            lst.append(\"background-color: yellow\")\n",
    "        else:\n",
    "            lst.append(\"\")\n",
    "    return lst\n",
    "df.style.apply(highlight_max,axis = 0,subset = ['b','c'])\n",
    "# 创建样式方法，每列最大值填充黄色\n",
    "# axis：0为列，1为行，默认为0\n",
    "# subset：索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style  type=\"text/css\" >\n",
       "    #T_00fdc9fa_43cb_11e8_b933_c821585077f5row2_col1 {\n",
       "            background-color:  yellow;\n",
       "        }    #T_00fdc9fa_43cb_11e8_b933_c821585077f5row3_col3 {\n",
       "            background-color:  yellow;\n",
       "        }    #T_00fdc9fa_43cb_11e8_b933_c821585077f5row4_col3 {\n",
       "            background-color:  yellow;\n",
       "        }    #T_00fdc9fa_43cb_11e8_b933_c821585077f5row5_col3 {\n",
       "            background-color:  yellow;\n",
       "        }</style>  \n",
       "<table id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5\" > \n",
       "<thead>    <tr> \n",
       "        <th class=\"blank level0\" ></th> \n",
       "        <th class=\"col_heading level0 col0\" >a</th> \n",
       "        <th class=\"col_heading level0 col1\" >b</th> \n",
       "        <th class=\"col_heading level0 col2\" >c</th> \n",
       "        <th class=\"col_heading level0 col3\" >d</th> \n",
       "    </tr></thead> \n",
       "<tbody>    <tr> \n",
       "        <th id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5level0_row0\" class=\"row_heading level0 row0\" >0</th> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row0_col0\" class=\"data row0 col0\" >-0.23073</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row0_col1\" class=\"data row0 col1\" >-1.15253</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row0_col2\" class=\"data row0 col2\" >0.284767</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row0_col3\" class=\"data row0 col3\" >0.225296</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5level0_row1\" class=\"row_heading level0 row1\" >1</th> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row1_col0\" class=\"data row1 col0\" >0.0533441</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row1_col1\" class=\"data row1 col1\" >1.04581</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row1_col2\" class=\"data row1 col2\" >-1.04923</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row1_col3\" class=\"data row1 col3\" >0.418713</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5level0_row2\" class=\"row_heading level0 row2\" >2</th> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row2_col0\" class=\"data row2 col0\" >-0.268366</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row2_col1\" class=\"data row2 col1\" >0.304776</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row2_col2\" class=\"data row2 col2\" >-0.917374</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row2_col3\" class=\"data row2 col3\" >-1.84995</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5level0_row3\" class=\"row_heading level0 row3\" >3</th> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row3_col0\" class=\"data row3 col0\" >-1.6807</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row3_col1\" class=\"data row3 col1\" >-0.489752</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row3_col2\" class=\"data row3 col2\" >0.00459406</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row3_col3\" class=\"data row3 col3\" >0.646842</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5level0_row4\" class=\"row_heading level0 row4\" >4</th> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row4_col0\" class=\"data row4 col0\" >-1.57819</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row4_col1\" class=\"data row4 col1\" >-1.30899</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row4_col2\" class=\"data row4 col2\" >-0.641586</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row4_col3\" class=\"data row4 col3\" >-1.10718</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5level0_row5\" class=\"row_heading level0 row5\" >5</th> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row5_col0\" class=\"data row5 col0\" >1.9277</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row5_col1\" class=\"data row5 col1\" >0.0218769</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row5_col2\" class=\"data row5 col2\" >0.349648</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row5_col3\" class=\"data row5 col3\" >0.170425</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5level0_row6\" class=\"row_heading level0 row6\" >6</th> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row6_col0\" class=\"data row6 col0\" >-0.321177</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row6_col1\" class=\"data row6 col1\" >1.25042</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row6_col2\" class=\"data row6 col2\" >0.889758</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row6_col3\" class=\"data row6 col3\" >0.682751</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5level0_row7\" class=\"row_heading level0 row7\" >7</th> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row7_col0\" class=\"data row7 col0\" >-1.2752</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row7_col1\" class=\"data row7 col1\" >0.0601818</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row7_col2\" class=\"data row7 col2\" >-0.315165</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row7_col3\" class=\"data row7 col3\" >-2.41086</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5level0_row8\" class=\"row_heading level0 row8\" >8</th> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row8_col0\" class=\"data row8 col0\" >1.55271</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row8_col1\" class=\"data row8 col1\" >-0.408844</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row8_col2\" class=\"data row8 col2\" >-0.230754</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row8_col3\" class=\"data row8 col3\" >0.166473</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5level0_row9\" class=\"row_heading level0 row9\" >9</th> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row9_col0\" class=\"data row9 col0\" >0.797423</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row9_col1\" class=\"data row9 col1\" >1.41495</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row9_col2\" class=\"data row9 col2\" >-0.240908</td> \n",
       "        <td id=\"T_00fdc9fa_43cb_11e8_b933_c821585077f5row9_col3\" class=\"data row9 col3\" >-0.0387529</td> \n",
       "    </tr></tbody> \n",
       "</table> "
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x2608307cc18>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 样式索引，切片\n",
    "\n",
    "df.style.apply(highlight_max,axis = 1,\n",
    "              subset = pd.IndexSlice[2:5,['b','d']])\n",
    "# 通过pd.IndexSlice[]来调用切片\n",
    "# 也可以：df[2:5].style.apply(highlight_max,subset = ['b','d'])    --->   先索引行然后在做样式"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3.14---表格显示控制\n",
    "## df.style.format()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "          a         b         c         d\n",
      "0 -0.137801  0.772792  1.393487 -0.180456\n",
      "1  2.325892  0.758207  0.108352  1.224738\n",
      "2  0.119683 -0.689806  0.205490 -1.574194\n",
      "3  1.665960  1.356086  0.320996 -0.564466\n",
      "4 -1.674796 -0.203297  0.008391 -0.057351\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<style  type=\"text/css\" >\n",
       "</style>  \n",
       "<table id=\"T_0dde73e2_43cc_11e8_bb61_c821585077f5\" > \n",
       "<thead>    <tr> \n",
       "        <th class=\"blank level0\" ></th> \n",
       "        <th class=\"col_heading level0 col0\" >a</th> \n",
       "        <th class=\"col_heading level0 col1\" >b</th> \n",
       "        <th class=\"col_heading level0 col2\" >c</th> \n",
       "        <th class=\"col_heading level0 col3\" >d</th> \n",
       "    </tr></thead> \n",
       "<tbody>    <tr> \n",
       "        <th id=\"T_0dde73e2_43cc_11e8_bb61_c821585077f5level0_row0\" class=\"row_heading level0 row0\" >0</th> \n",
       "        <td id=\"T_0dde73e2_43cc_11e8_bb61_c821585077f5row0_col0\" class=\"data row0 col0\" >-13.78%</td> \n",
       "        <td id=\"T_0dde73e2_43cc_11e8_bb61_c821585077f5row0_col1\" class=\"data row0 col1\" >77.28%</td> \n",
       "        <td id=\"T_0dde73e2_43cc_11e8_bb61_c821585077f5row0_col2\" class=\"data row0 col2\" >139.35%</td> \n",
       "        <td id=\"T_0dde73e2_43cc_11e8_bb61_c821585077f5row0_col3\" class=\"data row0 col3\" >-18.05%</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_0dde73e2_43cc_11e8_bb61_c821585077f5level0_row1\" class=\"row_heading level0 row1\" >1</th> \n",
       "        <td id=\"T_0dde73e2_43cc_11e8_bb61_c821585077f5row1_col0\" class=\"data row1 col0\" >232.59%</td> \n",
       "        <td id=\"T_0dde73e2_43cc_11e8_bb61_c821585077f5row1_col1\" class=\"data row1 col1\" >75.82%</td> \n",
       "        <td id=\"T_0dde73e2_43cc_11e8_bb61_c821585077f5row1_col2\" class=\"data row1 col2\" >10.84%</td> \n",
       "        <td id=\"T_0dde73e2_43cc_11e8_bb61_c821585077f5row1_col3\" class=\"data row1 col3\" >122.47%</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_0dde73e2_43cc_11e8_bb61_c821585077f5level0_row2\" class=\"row_heading level0 row2\" >2</th> \n",
       "        <td id=\"T_0dde73e2_43cc_11e8_bb61_c821585077f5row2_col0\" class=\"data row2 col0\" >11.97%</td> \n",
       "        <td id=\"T_0dde73e2_43cc_11e8_bb61_c821585077f5row2_col1\" class=\"data row2 col1\" >-68.98%</td> \n",
       "        <td id=\"T_0dde73e2_43cc_11e8_bb61_c821585077f5row2_col2\" class=\"data row2 col2\" >20.55%</td> \n",
       "        <td id=\"T_0dde73e2_43cc_11e8_bb61_c821585077f5row2_col3\" class=\"data row2 col3\" >-157.42%</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_0dde73e2_43cc_11e8_bb61_c821585077f5level0_row3\" class=\"row_heading level0 row3\" >3</th> \n",
       "        <td id=\"T_0dde73e2_43cc_11e8_bb61_c821585077f5row3_col0\" class=\"data row3 col0\" >166.60%</td> \n",
       "        <td id=\"T_0dde73e2_43cc_11e8_bb61_c821585077f5row3_col1\" class=\"data row3 col1\" >135.61%</td> \n",
       "        <td id=\"T_0dde73e2_43cc_11e8_bb61_c821585077f5row3_col2\" class=\"data row3 col2\" >32.10%</td> \n",
       "        <td id=\"T_0dde73e2_43cc_11e8_bb61_c821585077f5row3_col3\" class=\"data row3 col3\" >-56.45%</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_0dde73e2_43cc_11e8_bb61_c821585077f5level0_row4\" class=\"row_heading level0 row4\" >4</th> \n",
       "        <td id=\"T_0dde73e2_43cc_11e8_bb61_c821585077f5row4_col0\" class=\"data row4 col0\" >-167.48%</td> \n",
       "        <td id=\"T_0dde73e2_43cc_11e8_bb61_c821585077f5row4_col1\" class=\"data row4 col1\" >-20.33%</td> \n",
       "        <td id=\"T_0dde73e2_43cc_11e8_bb61_c821585077f5row4_col2\" class=\"data row4 col2\" >0.84%</td> \n",
       "        <td id=\"T_0dde73e2_43cc_11e8_bb61_c821585077f5row4_col3\" class=\"data row4 col3\" >-5.74%</td> \n",
       "    </tr></tbody> \n",
       "</table> "
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x2608309b208>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 按照百分数显示\n",
    "\n",
    "df = pd.DataFrame(np.random.randn(10,4),columns = list('abcd'))\n",
    "print(df.head())\n",
    "df.head().style.format(\"{:.2%}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style  type=\"text/css\" >\n",
       "</style>  \n",
       "<table id=\"T_6492446e_43cc_11e8_86df_c821585077f5\" > \n",
       "<thead>    <tr> \n",
       "        <th class=\"blank level0\" ></th> \n",
       "        <th class=\"col_heading level0 col0\" >a</th> \n",
       "        <th class=\"col_heading level0 col1\" >b</th> \n",
       "        <th class=\"col_heading level0 col2\" >c</th> \n",
       "        <th class=\"col_heading level0 col3\" >d</th> \n",
       "    </tr></thead> \n",
       "<tbody>    <tr> \n",
       "        <th id=\"T_6492446e_43cc_11e8_86df_c821585077f5level0_row0\" class=\"row_heading level0 row0\" >0</th> \n",
       "        <td id=\"T_6492446e_43cc_11e8_86df_c821585077f5row0_col0\" class=\"data row0 col0\" >-0.1378</td> \n",
       "        <td id=\"T_6492446e_43cc_11e8_86df_c821585077f5row0_col1\" class=\"data row0 col1\" >0.7728</td> \n",
       "        <td id=\"T_6492446e_43cc_11e8_86df_c821585077f5row0_col2\" class=\"data row0 col2\" >1.3935</td> \n",
       "        <td id=\"T_6492446e_43cc_11e8_86df_c821585077f5row0_col3\" class=\"data row0 col3\" >-0.1805</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_6492446e_43cc_11e8_86df_c821585077f5level0_row1\" class=\"row_heading level0 row1\" >1</th> \n",
       "        <td id=\"T_6492446e_43cc_11e8_86df_c821585077f5row1_col0\" class=\"data row1 col0\" >2.3259</td> \n",
       "        <td id=\"T_6492446e_43cc_11e8_86df_c821585077f5row1_col1\" class=\"data row1 col1\" >0.7582</td> \n",
       "        <td id=\"T_6492446e_43cc_11e8_86df_c821585077f5row1_col2\" class=\"data row1 col2\" >0.1084</td> \n",
       "        <td id=\"T_6492446e_43cc_11e8_86df_c821585077f5row1_col3\" class=\"data row1 col3\" >1.2247</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_6492446e_43cc_11e8_86df_c821585077f5level0_row2\" class=\"row_heading level0 row2\" >2</th> \n",
       "        <td id=\"T_6492446e_43cc_11e8_86df_c821585077f5row2_col0\" class=\"data row2 col0\" >0.1197</td> \n",
       "        <td id=\"T_6492446e_43cc_11e8_86df_c821585077f5row2_col1\" class=\"data row2 col1\" >-0.6898</td> \n",
       "        <td id=\"T_6492446e_43cc_11e8_86df_c821585077f5row2_col2\" class=\"data row2 col2\" >0.2055</td> \n",
       "        <td id=\"T_6492446e_43cc_11e8_86df_c821585077f5row2_col3\" class=\"data row2 col3\" >-1.5742</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_6492446e_43cc_11e8_86df_c821585077f5level0_row3\" class=\"row_heading level0 row3\" >3</th> \n",
       "        <td id=\"T_6492446e_43cc_11e8_86df_c821585077f5row3_col0\" class=\"data row3 col0\" >1.6660</td> \n",
       "        <td id=\"T_6492446e_43cc_11e8_86df_c821585077f5row3_col1\" class=\"data row3 col1\" >1.3561</td> \n",
       "        <td id=\"T_6492446e_43cc_11e8_86df_c821585077f5row3_col2\" class=\"data row3 col2\" >0.3210</td> \n",
       "        <td id=\"T_6492446e_43cc_11e8_86df_c821585077f5row3_col3\" class=\"data row3 col3\" >-0.5645</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_6492446e_43cc_11e8_86df_c821585077f5level0_row4\" class=\"row_heading level0 row4\" >4</th> \n",
       "        <td id=\"T_6492446e_43cc_11e8_86df_c821585077f5row4_col0\" class=\"data row4 col0\" >-1.6748</td> \n",
       "        <td id=\"T_6492446e_43cc_11e8_86df_c821585077f5row4_col1\" class=\"data row4 col1\" >-0.2033</td> \n",
       "        <td id=\"T_6492446e_43cc_11e8_86df_c821585077f5row4_col2\" class=\"data row4 col2\" >0.0084</td> \n",
       "        <td id=\"T_6492446e_43cc_11e8_86df_c821585077f5row4_col3\" class=\"data row4 col3\" >-0.0574</td> \n",
       "    </tr></tbody> \n",
       "</table> "
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x2608309b828>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 显示小数点数\n",
    "\n",
    "df.head().style.format(\"{:.4f}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style  type=\"text/css\" >\n",
       "</style>  \n",
       "<table id=\"T_c7de7e12_43cc_11e8_bcba_c821585077f5\" > \n",
       "<thead>    <tr> \n",
       "        <th class=\"blank level0\" ></th> \n",
       "        <th class=\"col_heading level0 col0\" >a</th> \n",
       "        <th class=\"col_heading level0 col1\" >b</th> \n",
       "        <th class=\"col_heading level0 col2\" >c</th> \n",
       "        <th class=\"col_heading level0 col3\" >d</th> \n",
       "    </tr></thead> \n",
       "<tbody>    <tr> \n",
       "        <th id=\"T_c7de7e12_43cc_11e8_bcba_c821585077f5level0_row0\" class=\"row_heading level0 row0\" >0</th> \n",
       "        <td id=\"T_c7de7e12_43cc_11e8_bcba_c821585077f5row0_col0\" class=\"data row0 col0\" >-0.14</td> \n",
       "        <td id=\"T_c7de7e12_43cc_11e8_bcba_c821585077f5row0_col1\" class=\"data row0 col1\" >+0.77</td> \n",
       "        <td id=\"T_c7de7e12_43cc_11e8_bcba_c821585077f5row0_col2\" class=\"data row0 col2\" >+1.39</td> \n",
       "        <td id=\"T_c7de7e12_43cc_11e8_bcba_c821585077f5row0_col3\" class=\"data row0 col3\" >-0.18</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_c7de7e12_43cc_11e8_bcba_c821585077f5level0_row1\" class=\"row_heading level0 row1\" >1</th> \n",
       "        <td id=\"T_c7de7e12_43cc_11e8_bcba_c821585077f5row1_col0\" class=\"data row1 col0\" >+2.33</td> \n",
       "        <td id=\"T_c7de7e12_43cc_11e8_bcba_c821585077f5row1_col1\" class=\"data row1 col1\" >+0.76</td> \n",
       "        <td id=\"T_c7de7e12_43cc_11e8_bcba_c821585077f5row1_col2\" class=\"data row1 col2\" >+0.11</td> \n",
       "        <td id=\"T_c7de7e12_43cc_11e8_bcba_c821585077f5row1_col3\" class=\"data row1 col3\" >+1.22</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_c7de7e12_43cc_11e8_bcba_c821585077f5level0_row2\" class=\"row_heading level0 row2\" >2</th> \n",
       "        <td id=\"T_c7de7e12_43cc_11e8_bcba_c821585077f5row2_col0\" class=\"data row2 col0\" >+0.12</td> \n",
       "        <td id=\"T_c7de7e12_43cc_11e8_bcba_c821585077f5row2_col1\" class=\"data row2 col1\" >-0.69</td> \n",
       "        <td id=\"T_c7de7e12_43cc_11e8_bcba_c821585077f5row2_col2\" class=\"data row2 col2\" >+0.21</td> \n",
       "        <td id=\"T_c7de7e12_43cc_11e8_bcba_c821585077f5row2_col3\" class=\"data row2 col3\" >-1.57</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_c7de7e12_43cc_11e8_bcba_c821585077f5level0_row3\" class=\"row_heading level0 row3\" >3</th> \n",
       "        <td id=\"T_c7de7e12_43cc_11e8_bcba_c821585077f5row3_col0\" class=\"data row3 col0\" >+1.67</td> \n",
       "        <td id=\"T_c7de7e12_43cc_11e8_bcba_c821585077f5row3_col1\" class=\"data row3 col1\" >+1.36</td> \n",
       "        <td id=\"T_c7de7e12_43cc_11e8_bcba_c821585077f5row3_col2\" class=\"data row3 col2\" >+0.32</td> \n",
       "        <td id=\"T_c7de7e12_43cc_11e8_bcba_c821585077f5row3_col3\" class=\"data row3 col3\" >-0.56</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_c7de7e12_43cc_11e8_bcba_c821585077f5level0_row4\" class=\"row_heading level0 row4\" >4</th> \n",
       "        <td id=\"T_c7de7e12_43cc_11e8_bcba_c821585077f5row4_col0\" class=\"data row4 col0\" >-1.67</td> \n",
       "        <td id=\"T_c7de7e12_43cc_11e8_bcba_c821585077f5row4_col1\" class=\"data row4 col1\" >-0.20</td> \n",
       "        <td id=\"T_c7de7e12_43cc_11e8_bcba_c821585077f5row4_col2\" class=\"data row4 col2\" >+0.01</td> \n",
       "        <td id=\"T_c7de7e12_43cc_11e8_bcba_c821585077f5row4_col3\" class=\"data row4 col3\" >-0.06</td> \n",
       "    </tr></tbody> \n",
       "</table> "
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x2608309b908>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 显示正负数\n",
    "\n",
    "df.head().style.format(\"{:+.2f}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style  type=\"text/css\" >\n",
       "</style>  \n",
       "<table id=\"T_33366da2_43cd_11e8_8ea7_c821585077f5\" > \n",
       "<thead>    <tr> \n",
       "        <th class=\"blank level0\" ></th> \n",
       "        <th class=\"col_heading level0 col0\" >a</th> \n",
       "        <th class=\"col_heading level0 col1\" >b</th> \n",
       "        <th class=\"col_heading level0 col2\" >c</th> \n",
       "        <th class=\"col_heading level0 col3\" >d</th> \n",
       "    </tr></thead> \n",
       "<tbody>    <tr> \n",
       "        <th id=\"T_33366da2_43cd_11e8_8ea7_c821585077f5level0_row0\" class=\"row_heading level0 row0\" >0</th> \n",
       "        <td id=\"T_33366da2_43cd_11e8_8ea7_c821585077f5row0_col0\" class=\"data row0 col0\" >-0.137801</td> \n",
       "        <td id=\"T_33366da2_43cd_11e8_8ea7_c821585077f5row0_col1\" class=\"data row0 col1\" >77.28%</td> \n",
       "        <td id=\"T_33366da2_43cd_11e8_8ea7_c821585077f5row0_col2\" class=\"data row0 col2\" >+1.393</td> \n",
       "        <td id=\"T_33366da2_43cd_11e8_8ea7_c821585077f5row0_col3\" class=\"data row0 col3\" >-0.180</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_33366da2_43cd_11e8_8ea7_c821585077f5level0_row1\" class=\"row_heading level0 row1\" >1</th> \n",
       "        <td id=\"T_33366da2_43cd_11e8_8ea7_c821585077f5row1_col0\" class=\"data row1 col0\" >2.32589</td> \n",
       "        <td id=\"T_33366da2_43cd_11e8_8ea7_c821585077f5row1_col1\" class=\"data row1 col1\" >75.82%</td> \n",
       "        <td id=\"T_33366da2_43cd_11e8_8ea7_c821585077f5row1_col2\" class=\"data row1 col2\" >+0.108</td> \n",
       "        <td id=\"T_33366da2_43cd_11e8_8ea7_c821585077f5row1_col3\" class=\"data row1 col3\" >1.225</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_33366da2_43cd_11e8_8ea7_c821585077f5level0_row2\" class=\"row_heading level0 row2\" >2</th> \n",
       "        <td id=\"T_33366da2_43cd_11e8_8ea7_c821585077f5row2_col0\" class=\"data row2 col0\" >0.119683</td> \n",
       "        <td id=\"T_33366da2_43cd_11e8_8ea7_c821585077f5row2_col1\" class=\"data row2 col1\" >-68.98%</td> \n",
       "        <td id=\"T_33366da2_43cd_11e8_8ea7_c821585077f5row2_col2\" class=\"data row2 col2\" >+0.205</td> \n",
       "        <td id=\"T_33366da2_43cd_11e8_8ea7_c821585077f5row2_col3\" class=\"data row2 col3\" >-1.574</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_33366da2_43cd_11e8_8ea7_c821585077f5level0_row3\" class=\"row_heading level0 row3\" >3</th> \n",
       "        <td id=\"T_33366da2_43cd_11e8_8ea7_c821585077f5row3_col0\" class=\"data row3 col0\" >1.66596</td> \n",
       "        <td id=\"T_33366da2_43cd_11e8_8ea7_c821585077f5row3_col1\" class=\"data row3 col1\" >135.61%</td> \n",
       "        <td id=\"T_33366da2_43cd_11e8_8ea7_c821585077f5row3_col2\" class=\"data row3 col2\" >+0.321</td> \n",
       "        <td id=\"T_33366da2_43cd_11e8_8ea7_c821585077f5row3_col3\" class=\"data row3 col3\" >-0.564</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_33366da2_43cd_11e8_8ea7_c821585077f5level0_row4\" class=\"row_heading level0 row4\" >4</th> \n",
       "        <td id=\"T_33366da2_43cd_11e8_8ea7_c821585077f5row4_col0\" class=\"data row4 col0\" >-1.6748</td> \n",
       "        <td id=\"T_33366da2_43cd_11e8_8ea7_c821585077f5row4_col1\" class=\"data row4 col1\" >-20.33%</td> \n",
       "        <td id=\"T_33366da2_43cd_11e8_8ea7_c821585077f5row4_col2\" class=\"data row4 col2\" >+0.008</td> \n",
       "        <td id=\"T_33366da2_43cd_11e8_8ea7_c821585077f5row4_col3\" class=\"data row4 col3\" >-0.057</td> \n",
       "    </tr></tbody> \n",
       "</table> "
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x2608307ceb8>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 分列显示\n",
    "\n",
    "df.head().style.format({'b':\"{:.2%}\",'c':\"{:+.3f}\",'d':\"{:.3f}\"})"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3.15---表格样式调用\n",
    "## STyler内置样式调用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style  type=\"text/css\" >\n",
       "    #T_0699a1c2_43ce_11e8_829b_c821585077f5row2_col0 {\n",
       "            background-color:  red;\n",
       "        }</style>  \n",
       "<table id=\"T_0699a1c2_43ce_11e8_829b_c821585077f5\" > \n",
       "<thead>    <tr> \n",
       "        <th class=\"blank level0\" ></th> \n",
       "        <th class=\"col_heading level0 col0\" >A</th> \n",
       "        <th class=\"col_heading level0 col1\" >B</th> \n",
       "        <th class=\"col_heading level0 col2\" >C</th> \n",
       "        <th class=\"col_heading level0 col3\" >D</th> \n",
       "    </tr></thead> \n",
       "<tbody>    <tr> \n",
       "        <th id=\"T_0699a1c2_43ce_11e8_829b_c821585077f5level0_row0\" class=\"row_heading level0 row0\" >0</th> \n",
       "        <td id=\"T_0699a1c2_43ce_11e8_829b_c821585077f5row0_col0\" class=\"data row0 col0\" >0.816101</td> \n",
       "        <td id=\"T_0699a1c2_43ce_11e8_829b_c821585077f5row0_col1\" class=\"data row0 col1\" >0.147947</td> \n",
       "        <td id=\"T_0699a1c2_43ce_11e8_829b_c821585077f5row0_col2\" class=\"data row0 col2\" >0.79318</td> \n",
       "        <td id=\"T_0699a1c2_43ce_11e8_829b_c821585077f5row0_col3\" class=\"data row0 col3\" >0.693021</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_0699a1c2_43ce_11e8_829b_c821585077f5level0_row1\" class=\"row_heading level0 row1\" >1</th> \n",
       "        <td id=\"T_0699a1c2_43ce_11e8_829b_c821585077f5row1_col0\" class=\"data row1 col0\" >0.682932</td> \n",
       "        <td id=\"T_0699a1c2_43ce_11e8_829b_c821585077f5row1_col1\" class=\"data row1 col1\" >0.0438644</td> \n",
       "        <td id=\"T_0699a1c2_43ce_11e8_829b_c821585077f5row1_col2\" class=\"data row1 col2\" >0.182832</td> \n",
       "        <td id=\"T_0699a1c2_43ce_11e8_829b_c821585077f5row1_col3\" class=\"data row1 col3\" >0.76382</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_0699a1c2_43ce_11e8_829b_c821585077f5level0_row2\" class=\"row_heading level0 row2\" >2</th> \n",
       "        <td id=\"T_0699a1c2_43ce_11e8_829b_c821585077f5row2_col0\" class=\"data row2 col0\" >nan</td> \n",
       "        <td id=\"T_0699a1c2_43ce_11e8_829b_c821585077f5row2_col1\" class=\"data row2 col1\" >0.433107</td> \n",
       "        <td id=\"T_0699a1c2_43ce_11e8_829b_c821585077f5row2_col2\" class=\"data row2 col2\" >0.536244</td> \n",
       "        <td id=\"T_0699a1c2_43ce_11e8_829b_c821585077f5row2_col3\" class=\"data row2 col3\" >0.461644</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_0699a1c2_43ce_11e8_829b_c821585077f5level0_row3\" class=\"row_heading level0 row3\" >3</th> \n",
       "        <td id=\"T_0699a1c2_43ce_11e8_829b_c821585077f5row3_col0\" class=\"data row3 col0\" >0.32712</td> \n",
       "        <td id=\"T_0699a1c2_43ce_11e8_829b_c821585077f5row3_col1\" class=\"data row3 col1\" >0.0183903</td> \n",
       "        <td id=\"T_0699a1c2_43ce_11e8_829b_c821585077f5row3_col2\" class=\"data row3 col2\" >0.891104</td> \n",
       "        <td id=\"T_0699a1c2_43ce_11e8_829b_c821585077f5row3_col3\" class=\"data row3 col3\" >0.258875</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_0699a1c2_43ce_11e8_829b_c821585077f5level0_row4\" class=\"row_heading level0 row4\" >4</th> \n",
       "        <td id=\"T_0699a1c2_43ce_11e8_829b_c821585077f5row4_col0\" class=\"data row4 col0\" >0.734065</td> \n",
       "        <td id=\"T_0699a1c2_43ce_11e8_829b_c821585077f5row4_col1\" class=\"data row4 col1\" >0.348591</td> \n",
       "        <td id=\"T_0699a1c2_43ce_11e8_829b_c821585077f5row4_col2\" class=\"data row4 col2\" >0.834945</td> \n",
       "        <td id=\"T_0699a1c2_43ce_11e8_829b_c821585077f5row4_col3\" class=\"data row4 col3\" >0.202286</td> \n",
       "    </tr></tbody> \n",
       "</table> "
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x2608312d208>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 定位空值\n",
    "\n",
    "df = pd.DataFrame(np.random.rand(5,4),columns = list(\"ABCD\"))\n",
    "df['A'][2] = np.nan\n",
    "df.style.highlight_null(null_color='red')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style  type=\"text/css\" >\n",
       "    #T_a5763d02_43d0_11e8_99e8_c821585077f5row0_col0 {\n",
       "            background-color:  #f7fcf5;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row0_col1 {\n",
       "            background-color:  #73c476;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row0_col2 {\n",
       "            background-color:  #f0f9ed;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row0_col3 {\n",
       "            background-color:  #a3da9d;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row1_col0 {\n",
       "            background-color:  #f7fcf5;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row1_col1 {\n",
       "            background-color:  #73c476;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row1_col2 {\n",
       "            background-color:  #cfecc9;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row1_col3 {\n",
       "            background-color:  #f5fbf2;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row2_col0 {\n",
       "            background-color:  #f3faf0;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row2_col1 {\n",
       "            background-color:  #a2d99c;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row2_col2 {\n",
       "            background-color:  #f7fcf5;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row2_col3 {\n",
       "            background-color:  #75c477;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row3_col0 {\n",
       "            background-color:  #95d391;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row3_col1 {\n",
       "            background-color:  #f7fcf5;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row3_col2 {\n",
       "            background-color:  #c7e9c0;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row3_col3 {\n",
       "            background-color:  #73c476;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row4_col0 {\n",
       "            background-color:  #f7fcf5;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row4_col1 {\n",
       "            background-color:  #c2e7bb;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row4_col2 {\n",
       "            background-color:  #73c476;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row4_col3 {\n",
       "            background-color:  #d7efd1;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row5_col0 {\n",
       "            background-color:  #b5e1ae;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row5_col1 {\n",
       "            background-color:  #73c476;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row5_col2 {\n",
       "            background-color:  #f7fcf5;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row5_col3 {\n",
       "            background-color:  #e9f7e5;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row6_col0 {\n",
       "            background-color:  #f7fcf5;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row6_col1 {\n",
       "            background-color:  #d5efcf;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row6_col2 {\n",
       "            background-color:  #75c477;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row6_col3 {\n",
       "            background-color:  #79c67a;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row7_col0 {\n",
       "            background-color:  #9ed798;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row7_col1 {\n",
       "            background-color:  #f7fcf5;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row7_col2 {\n",
       "            background-color:  #f4fbf2;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row7_col3 {\n",
       "            background-color:  #73c476;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row8_col0 {\n",
       "            background-color:  #f7fcf5;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row8_col1 {\n",
       "            background-color:  #73c476;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row8_col2 {\n",
       "            background-color:  #d3eecd;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row8_col3 {\n",
       "            background-color:  #76c578;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row9_col0 {\n",
       "            background-color:  #f2faef;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row9_col1 {\n",
       "            background-color:  #73c476;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row9_col2 {\n",
       "            background-color:  #97d492;\n",
       "        }    #T_a5763d02_43d0_11e8_99e8_c821585077f5row9_col3 {\n",
       "            background-color:  #f7fcf5;\n",
       "        }</style>  \n",
       "<table id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5\" > \n",
       "<thead>    <tr> \n",
       "        <th class=\"blank level0\" ></th> \n",
       "        <th class=\"col_heading level0 col0\" >A</th> \n",
       "        <th class=\"col_heading level0 col1\" >B</th> \n",
       "        <th class=\"col_heading level0 col2\" >C</th> \n",
       "        <th class=\"col_heading level0 col3\" >D</th> \n",
       "    </tr></thead> \n",
       "<tbody>    <tr> \n",
       "        <th id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5level0_row0\" class=\"row_heading level0 row0\" >0</th> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row0_col0\" class=\"data row0 col0\" >0.19826</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row0_col1\" class=\"data row0 col1\" >0.929015</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row0_col2\" class=\"data row0 col2\" >0.272112</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row0_col3\" class=\"data row0 col3\" >0.737562</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5level0_row1\" class=\"row_heading level0 row1\" >1</th> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row1_col0\" class=\"data row1 col0\" >6.31945e-05</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row1_col1\" class=\"data row1 col1\" >0.722313</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row1_col2\" class=\"data row1 col2\" >0.310946</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row1_col3\" class=\"data row1 col3\" >0.0246118</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5level0_row2\" class=\"row_heading level0 row2\" >2</th> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row2_col0\" class=\"data row2 col0\" >0.127526</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row2_col1\" class=\"data row2 col1\" >0.54559</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row2_col2\" class=\"data row2 col2\" >0.0916403</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row2_col3\" class=\"data row2 col3\" >0.700322</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5level0_row3\" class=\"row_heading level0 row3\" >3</th> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row3_col0\" class=\"data row3 col0\" >0.92052</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row3_col1\" class=\"data row3 col1\" >0.581225</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row3_col2\" class=\"data row3 col2\" >0.789389</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row3_col3\" class=\"data row3 col3\" >0.994849</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5level0_row4\" class=\"row_heading level0 row4\" >4</th> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row4_col0\" class=\"data row4 col0\" >0.381826</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row4_col1\" class=\"data row4 col1\" >0.690779</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row4_col2\" class=\"data row4 col2\" >0.9613</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row4_col3\" class=\"data row4 col3\" >0.597779</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5level0_row5\" class=\"row_heading level0 row5\" >5</th> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row5_col0\" class=\"data row5 col0\" >0.611536</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row5_col1\" class=\"data row5 col1\" >0.894641</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row5_col2\" class=\"data row5 col2\" >0.145632</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row5_col3\" class=\"data row5 col3\" >0.293858</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5level0_row6\" class=\"row_heading level0 row6\" >6</th> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row6_col0\" class=\"data row6 col0\" >0.1122</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row6_col1\" class=\"data row6 col1\" >0.411026</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row6_col2\" class=\"data row6 col2\" >0.884302</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row6_col3\" class=\"data row6 col3\" >0.863161</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5level0_row7\" class=\"row_heading level0 row7\" >7</th> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row7_col0\" class=\"data row7 col0\" >0.404155</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row7_col1\" class=\"data row7 col1\" >0.172886</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row7_col2\" class=\"data row7 col2\" >0.186822</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row7_col3\" class=\"data row7 col3\" >0.472567</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5level0_row8\" class=\"row_heading level0 row8\" >8</th> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row8_col0\" class=\"data row8 col0\" >0.19802</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row8_col1\" class=\"data row8 col1\" >0.944379</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row8_col2\" class=\"data row8 col2\" >0.498535</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row8_col3\" class=\"data row8 col3\" >0.935626</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5level0_row9\" class=\"row_heading level0 row9\" >9</th> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row9_col0\" class=\"data row9 col0\" >0.091746</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row9_col1\" class=\"data row9 col1\" >0.90366</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row9_col2\" class=\"data row9 col2\" >0.735698</td> \n",
       "        <td id=\"T_a5763d02_43d0_11e8_99e8_c821585077f5row9_col3\" class=\"data row9 col3\" >0.0271318</td> \n",
       "    </tr></tbody> \n",
       "</table> "
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x2608312dda0>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 色彩映射\n",
    "\n",
    "df = pd.DataFrame(np.random.rand(10,4),columns = list(\"ABCD\"))\n",
    "df.style.background_gradient(cmap = 'Greens',axis = 1,low = 0,high = 1)\n",
    "# cmap: 颜色\n",
    "# axis：映射参考，0为列，1为行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style  type=\"text/css\" >\n",
       "    #T_6e2145a4_43d1_11e8_96f9_c821585077f5row0_col0 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 2.1%, transparent 0%);\n",
       "        }    #T_6e2145a4_43d1_11e8_96f9_c821585077f5row0_col1 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 2.8%, transparent 0%);\n",
       "        }    #T_6e2145a4_43d1_11e8_96f9_c821585077f5row1_col0 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 100.0%, transparent 0%);\n",
       "        }    #T_6e2145a4_43d1_11e8_96f9_c821585077f5row1_col1 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 4.5%, transparent 0%);\n",
       "        }    #T_6e2145a4_43d1_11e8_96f9_c821585077f5row2_col0 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 2.8%, transparent 0%);\n",
       "        }    #T_6e2145a4_43d1_11e8_96f9_c821585077f5row2_col1 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 14.5%, transparent 0%);\n",
       "        }    #T_6e2145a4_43d1_11e8_96f9_c821585077f5row3_col0 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 56.9%, transparent 0%);\n",
       "        }    #T_6e2145a4_43d1_11e8_96f9_c821585077f5row3_col1 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 100.0%, transparent 0%);\n",
       "        }    #T_6e2145a4_43d1_11e8_96f9_c821585077f5row4_col0 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 38.3%, transparent 0%);\n",
       "        }    #T_6e2145a4_43d1_11e8_96f9_c821585077f5row4_col1 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 68.2%, transparent 0%);\n",
       "        }    #T_6e2145a4_43d1_11e8_96f9_c821585077f5row5_col0 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 93.8%, transparent 0%);\n",
       "        }    #T_6e2145a4_43d1_11e8_96f9_c821585077f5row5_col1 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "        }    #T_6e2145a4_43d1_11e8_96f9_c821585077f5row6_col0 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "        }    #T_6e2145a4_43d1_11e8_96f9_c821585077f5row6_col1 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 9.9%, transparent 0%);\n",
       "        }    #T_6e2145a4_43d1_11e8_96f9_c821585077f5row7_col0 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 31.9%, transparent 0%);\n",
       "        }    #T_6e2145a4_43d1_11e8_96f9_c821585077f5row7_col1 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 56.7%, transparent 0%);\n",
       "        }    #T_6e2145a4_43d1_11e8_96f9_c821585077f5row8_col0 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 64.6%, transparent 0%);\n",
       "        }    #T_6e2145a4_43d1_11e8_96f9_c821585077f5row8_col1 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 0.6%, transparent 0%);\n",
       "        }    #T_6e2145a4_43d1_11e8_96f9_c821585077f5row9_col0 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 76.9%, transparent 0%);\n",
       "        }    #T_6e2145a4_43d1_11e8_96f9_c821585077f5row9_col1 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 29.0%, transparent 0%);\n",
       "        }</style>  \n",
       "<table id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5\" > \n",
       "<thead>    <tr> \n",
       "        <th class=\"blank level0\" ></th> \n",
       "        <th class=\"col_heading level0 col0\" >A</th> \n",
       "        <th class=\"col_heading level0 col1\" >B</th> \n",
       "        <th class=\"col_heading level0 col2\" >C</th> \n",
       "        <th class=\"col_heading level0 col3\" >D</th> \n",
       "    </tr></thead> \n",
       "<tbody>    <tr> \n",
       "        <th id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5level0_row0\" class=\"row_heading level0 row0\" >0</th> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row0_col0\" class=\"data row0 col0\" >0.158156</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row0_col1\" class=\"data row0 col1\" >0.131662</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row0_col2\" class=\"data row0 col2\" >0.696928</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row0_col3\" class=\"data row0 col3\" >0.323981</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5level0_row1\" class=\"row_heading level0 row1\" >1</th> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row1_col0\" class=\"data row1 col0\" >0.998955</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row1_col1\" class=\"data row1 col1\" >0.146421</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row1_col2\" class=\"data row1 col2\" >0.967388</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row1_col3\" class=\"data row1 col3\" >0.489043</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5level0_row2\" class=\"row_heading level0 row2\" >2</th> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row2_col0\" class=\"data row2 col0\" >0.164986</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row2_col1\" class=\"data row2 col1\" >0.231471</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row2_col2\" class=\"data row2 col2\" >0.380393</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row2_col3\" class=\"data row2 col3\" >0.293783</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5level0_row3\" class=\"row_heading level0 row3\" >3</th> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row3_col0\" class=\"data row3 col0\" >0.629314</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row3_col1\" class=\"data row3 col1\" >0.960778</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row3_col2\" class=\"data row3 col2\" >0.832877</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row3_col3\" class=\"data row3 col3\" >0.277047</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5level0_row4\" class=\"row_heading level0 row4\" >4</th> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row4_col0\" class=\"data row4 col0\" >0.469546</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row4_col1\" class=\"data row4 col1\" >0.689595</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row4_col2\" class=\"data row4 col2\" >0.226948</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row4_col3\" class=\"data row4 col3\" >0.0828477</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5level0_row5\" class=\"row_heading level0 row5\" >5</th> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row5_col0\" class=\"data row5 col0\" >0.946106</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row5_col1\" class=\"data row5 col1\" >0.108099</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row5_col2\" class=\"data row5 col2\" >0.664916</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row5_col3\" class=\"data row5 col3\" >0.660803</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5level0_row6\" class=\"row_heading level0 row6\" >6</th> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row6_col0\" class=\"data row6 col0\" >0.140545</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row6_col1\" class=\"data row6 col1\" >0.192169</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row6_col2\" class=\"data row6 col2\" >0.533787</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row6_col3\" class=\"data row6 col3\" >0.112845</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5level0_row7\" class=\"row_heading level0 row7\" >7</th> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row7_col0\" class=\"data row7 col0\" >0.4143</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row7_col1\" class=\"data row7 col1\" >0.591382</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row7_col2\" class=\"data row7 col2\" >0.0235166</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row7_col3\" class=\"data row7 col3\" >0.589285</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5level0_row8\" class=\"row_heading level0 row8\" >8</th> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row8_col0\" class=\"data row8 col0\" >0.695249</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row8_col1\" class=\"data row8 col1\" >0.113361</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row8_col2\" class=\"data row8 col2\" >0.901049</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row8_col3\" class=\"data row8 col3\" >0.0141241</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5level0_row9\" class=\"row_heading level0 row9\" >9</th> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row9_col0\" class=\"data row9 col0\" >0.800434</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row9_col1\" class=\"data row9 col1\" >0.355469</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row9_col2\" class=\"data row9 col2\" >0.115479</td> \n",
       "        <td id=\"T_6e2145a4_43d1_11e8_96f9_c821585077f5row9_col3\" class=\"data row9 col3\" >0.851974</td> \n",
       "    </tr></tbody> \n",
       "</table> "
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x2608307c278>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 条形图\n",
    "\n",
    "df = pd.DataFrame(np.random.rand(10,4),columns = list(\"ABCD\"))\n",
    "df.style.bar(subset = ['A','B'],color = '#d65f5f',width = 100)\n",
    "# width: 最长长度在格子的占比"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style  type=\"text/css\" >\n",
       "    #T_6035a23a_43d2_11e8_8c38_c821585077f5row0_col0 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 72.3%, transparent 0%);\n",
       "            : ;\n",
       "        }    #T_6035a23a_43d2_11e8_8c38_c821585077f5row0_col1 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 72.1%, transparent 0%);\n",
       "            : ;\n",
       "        }    #T_6035a23a_43d2_11e8_8c38_c821585077f5row1_col0 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 32.4%, transparent 0%);\n",
       "            : ;\n",
       "        }    #T_6035a23a_43d2_11e8_8c38_c821585077f5row1_col1 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            : ;\n",
       "        }    #T_6035a23a_43d2_11e8_8c38_c821585077f5row2_col0 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background-color:  purple;\n",
       "        }    #T_6035a23a_43d2_11e8_8c38_c821585077f5row2_col1 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 40.4%, transparent 0%);\n",
       "            : ;\n",
       "        }    #T_6035a23a_43d2_11e8_8c38_c821585077f5row3_col0 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background-color:  purple;\n",
       "        }    #T_6035a23a_43d2_11e8_8c38_c821585077f5row3_col1 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 81.1%, transparent 0%);\n",
       "            : ;\n",
       "        }    #T_6035a23a_43d2_11e8_8c38_c821585077f5row4_col0 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 29.1%, transparent 0%);\n",
       "            : ;\n",
       "        }    #T_6035a23a_43d2_11e8_8c38_c821585077f5row4_col1 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 39.1%, transparent 0%);\n",
       "            : ;\n",
       "        }    #T_6035a23a_43d2_11e8_8c38_c821585077f5row5_col0 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 100.0%, transparent 0%);\n",
       "            : ;\n",
       "        }    #T_6035a23a_43d2_11e8_8c38_c821585077f5row5_col1 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 57.9%, transparent 0%);\n",
       "            : ;\n",
       "        }    #T_6035a23a_43d2_11e8_8c38_c821585077f5row6_col0 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 85.4%, transparent 0%);\n",
       "            : ;\n",
       "        }    #T_6035a23a_43d2_11e8_8c38_c821585077f5row6_col1 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 0.8%, transparent 0%);\n",
       "            : ;\n",
       "        }    #T_6035a23a_43d2_11e8_8c38_c821585077f5row7_col0 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 26.3%, transparent 0%);\n",
       "            : ;\n",
       "        }    #T_6035a23a_43d2_11e8_8c38_c821585077f5row7_col1 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 100.0%, transparent 0%);\n",
       "            : ;\n",
       "        }    #T_6035a23a_43d2_11e8_8c38_c821585077f5row8_col0 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 64.7%, transparent 0%);\n",
       "            : ;\n",
       "        }    #T_6035a23a_43d2_11e8_8c38_c821585077f5row8_col1 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 89.2%, transparent 0%);\n",
       "            : ;\n",
       "        }    #T_6035a23a_43d2_11e8_8c38_c821585077f5row9_col0 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            : ;\n",
       "        }    #T_6035a23a_43d2_11e8_8c38_c821585077f5row9_col1 {\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg,#d65f5f 47.0%, transparent 0%);\n",
       "            : ;\n",
       "        }</style>  \n",
       "<table id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5\" > \n",
       "<thead>    <tr> \n",
       "        <th class=\"blank level0\" ></th> \n",
       "        <th class=\"col_heading level0 col0\" >A</th> \n",
       "        <th class=\"col_heading level0 col1\" >B</th> \n",
       "        <th class=\"col_heading level0 col2\" >C</th> \n",
       "        <th class=\"col_heading level0 col3\" >D</th> \n",
       "    </tr></thead> \n",
       "<tbody>    <tr> \n",
       "        <th id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5level0_row0\" class=\"row_heading level0 row0\" >0</th> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row0_col0\" class=\"data row0 col0\" >0.742619</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row0_col1\" class=\"data row0 col1\" >0.669166</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row0_col2\" class=\"data row0 col2\" >0.583954</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row0_col3\" class=\"data row0 col3\" >0.904317</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5level0_row1\" class=\"row_heading level0 row1\" >1</th> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row1_col0\" class=\"data row1 col0\" >0.374322</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row1_col1\" class=\"data row1 col1\" >0.00681604</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row1_col2\" class=\"data row1 col2\" >0.290425</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row1_col3\" class=\"data row1 col3\" >0.425435</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5level0_row2\" class=\"row_heading level0 row2\" >2</th> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row2_col0\" class=\"data row2 col0\" >nan</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row2_col1\" class=\"data row2 col1\" >0.377587</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row2_col2\" class=\"data row2 col2\" >0.868583</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row2_col3\" class=\"data row2 col3\" >0.764427</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5level0_row3\" class=\"row_heading level0 row3\" >3</th> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row3_col0\" class=\"data row3 col0\" >nan</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row3_col1\" class=\"data row3 col1\" >0.752466</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row3_col2\" class=\"data row3 col2\" >0.206078</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row3_col3\" class=\"data row3 col3\" >0.725902</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5level0_row4\" class=\"row_heading level0 row4\" >4</th> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row4_col0\" class=\"data row4 col0\" >0.343125</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row4_col1\" class=\"data row4 col1\" >0.366123</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row4_col2\" class=\"data row4 col2\" >0.588702</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row4_col3\" class=\"data row4 col3\" >0.826</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5level0_row5\" class=\"row_heading level0 row5\" >5</th> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row5_col0\" class=\"data row5 col0\" >0.99791</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row5_col1\" class=\"data row5 col1\" >0.538491</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row5_col2\" class=\"data row5 col2\" >0.885587</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row5_col3\" class=\"data row5 col3\" >0.53326</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5level0_row6\" class=\"row_heading level0 row6\" >6</th> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row6_col0\" class=\"data row6 col0\" >0.863008</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row6_col1\" class=\"data row6 col1\" >0.014544</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row6_col2\" class=\"data row6 col2\" >0.593034</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row6_col3\" class=\"data row6 col3\" >0.5198</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5level0_row7\" class=\"row_heading level0 row7\" >7</th> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row7_col0\" class=\"data row7 col0\" >0.317435</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row7_col1\" class=\"data row7 col1\" >0.9257</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row7_col2\" class=\"data row7 col2\" >0.699342</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row7_col3\" class=\"data row7 col3\" >0.743785</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5level0_row8\" class=\"row_heading level0 row8\" >8</th> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row8_col0\" class=\"data row8 col0\" >0.672058</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row8_col1\" class=\"data row8 col1\" >0.826643</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row8_col2\" class=\"data row8 col2\" >0.480066</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row8_col3\" class=\"data row8 col3\" >0.375654</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5level0_row9\" class=\"row_heading level0 row9\" >9</th> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row9_col0\" class=\"data row9 col0\" >0.0747612</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row9_col1\" class=\"data row9 col1\" >0.438858</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row9_col2\" class=\"data row9 col2\" >0.117289</td> \n",
       "        <td id=\"T_6035a23a_43d2_11e8_8c38_c821585077f5row9_col3\" class=\"data row9 col3\" >0.32461</td> \n",
       "    </tr></tbody> \n",
       "</table> "
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x26083152940>"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 分段式构建样式\n",
    "\n",
    "df = pd.DataFrame(np.random.rand(10,4),columns = list(\"ABCD\"))\n",
    "df['A'][[3,2]] = np.nan\n",
    "df.style.\\\n",
    "    bar(subset = ['A','B'],color = '#d65f5f',width = 100).\\\n",
    "    highlight_null(null_color='purple')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
